<?php
// $Id: index.php 229 2008-03-03 13:27:42Z mikhail.miguel $

// 2007-08-01 K.OHWADA
// divid to config_manage_2.php
// email linkbroken_notify

// 2007-06-10 K.OHWADA
// WEBLINKS_DEBUG_LINK_CATLINK_BASIC_SQL
// form_cat_page

// 2007-03-25 K.OHWADA
// form_index

// 2007-03-01 K.OHWADA
// renew config table
// WEBLINKS_DEBUG_CATEGORY_BASIC_SQL

// 2006-12-10 K.OHWADA
// use happy_linux_debug

// 2006-10-01 K.OHWADA
// use happy_linux
// divid to config_manage_3.php
// google map

// 2006-05-15 K.OHWADA
// renewal

//=========================================================
// WebLinks Module
// porting form RSSC 
// 2006-05-15 K.OHWADA
//=========================================================

include_once 'admin_header.php';
include_once XOOPS_ROOT_PATH.'/modules/happy_linux/class/debug.php';
include_once XOOPS_ROOT_PATH.'/modules/happy_linux/class/config_base_handler.php';
include_once XOOPS_ROOT_PATH.'/modules/happy_linux/class/config_define_handler.php';
include_once XOOPS_ROOT_PATH.'/modules/happy_linux/class/config_store_handler.php';
include_once WEBLINKS_ROOT_PATH.'/include/weblinks_version.php';
include_once WEBLINKS_ROOT_PATH.'/class/weblinks_config2_handler.php';
include_once WEBLINKS_ROOT_PATH.'/class/weblinks_config2_define_handler.php';
include_once WEBLINKS_ROOT_PATH.'/class/weblinks_linkitem_handler.php';
include_once WEBLINKS_ROOT_PATH.'/class/weblinks_linkitem_define_handler.php';
include_once WEBLINKS_ROOT_PATH.'/class/weblinks_linkitem_store_handler.php';
include_once WEBLINKS_ROOT_PATH.'/class/weblinks_config_check_handler.php';
include_once WEBLINKS_ROOT_PATH.'/admin/admin_config_class.php';

$DIR_CONFIG = WEBLINKS_ROOT_PATH.'/cache';

// class
$class_debug  =& happy_linux_debug::getInstance();
$config_form  =& admin_config_form::getInstance();
$config_store =& admin_config_store::getInstance();

$op = $config_form->get_post_get_op();

// email linkbroken_notify
if ($op == 'listBrokenLinks')
{
	redirect_header("broken_list.php", 1, _WLS_BROKENREPORTS);
}
elseif ($op == 'init')
{
	if( !$config_form->check_token() ) 
	{
		xoops_cp_header();
		xoops_error("Token Error");
		echo "<br />\n";
		echo $config_form->get_token_error(1);
		echo "<br />\n";
	}
	else
	{
		$ret = $config_store->init();
		if ($ret)
		{
			redirect_header("index.php", 1, _WLS_DBUPDATED);
		}
		else
		{
			xoops_cp_header();
			xoops_error("DB Error");
			echo $config_store->getErrors(1);
		}
	}
}
elseif ($op == 'upgrade')
{
	if( !$config_form->check_token() ) 
	{
		xoops_cp_header();
		xoops_error("Token Error");
		echo "<br />\n";
		echo $config_form->get_token_error(1);
		echo "<br />\n";
	}
	else
	{
		$ret = $config_store->upgrade();
		if ($ret)
		{
			redirect_header("index.php", 1, _WLS_DBUPDATED);
		}
		else
		{
			xoops_cp_header();
			xoops_error("DB Error");
			echo $config_store->getErrors(1);
		}
	}
}
elseif ($op == 'template_clear')
{
	if( !$config_form->check_token() ) 
	{
		xoops_cp_header();
		xoops_error("Token Error");
		echo "<br />\n";
		echo $config_form->get_token_error(1);
		echo "<br />\n";
	}
	else
	{
		$config_store->template_clear();
		redirect_header("index.php", 1, _HAPPY_LINUX_CLEARED );
	}
}
else
{
	xoops_cp_header();
}

$config_store->print_style_sheet();

weblinks_admin_print_header();

if ( !$config_store->check_init() )
{
	$config_store->print_form_init();
}
elseif ( !$config_store->check_version() )
{
	$config_store->print_form_upgrade();
}
elseif ( !is_writable( $DIR_CONFIG ) )
{
	xoops_error( _AM_WEBLINKS_WARNING_NOT_WRITABLE );
	echo "<br />\n";
	echo "$DIR_CONFIG <br /><br />\n";
}
else
{
	weblinks_admin_print_menu();
	
	echo "<h4>". _AM_WEBLINKS_SERVER_ENV ."</h4>\n";
	echo "magic_quotes_gpc: ". intval( get_magic_quotes_gpc() ) ."<br />\n";
	echo "allow_url_fopen: ". intval( ini_get('allow_url_fopen') ) ."<br />\n";

	echo "<h4>". _AM_WEBLINKS_DEBUG_CONF ."</h4>\n";
	$debug_arr = array(
		'WEBLINKS_DEBUG_ERROR',
		'WEBLINKS_DEBUG_CONFIG2_SQL',
		'WEBLINKS_DEBUG_LINKITEM_SQL',
		'WEBLINKS_DEBUG_CATEGORY_SQL',
		'WEBLINKS_DEBUG_CATLINK_SQL',
		'WEBLINKS_DEBUG_LINK_SQL',
		'WEBLINKS_DEBUG_MODIFY_SQL',
		'WEBLINKS_DEBUG_BROKEN_SQL',
		'WEBLINKS_DEBUG_VOTEDATA_SQL',
		'WEBLINKS_DEBUG_TABLE_CHECK_SQL',
		'WEBLINKS_DEBUG_CONFIG2_BASIC_SQL',
		'WEBLINKS_DEBUG_LINKITEM_BASIC_SQL',
		'WEBLINKS_DEBUG_CATEGORY_BASIC_SQL',
		'WEBLINKS_DEBUG_CATLINK_BASIC_SQL',	
		'WEBLINKS_DEBUG_LINK_BASIC_SQL',	
		'WEBLINKS_DEBUG_LINK_CATLINK_BASIC_SQL',
		'WEBLINKS_DEBUG_TIME',
		'WEBLINKS_DEV_PERMIT',
		'WEBLINKS_DEV_PERMIT_GUEST',
	);

	$class_debug->print_constant_by_array( $debug_arr, _AM_WEBLINKS_ALL_GREEN );

	$config_form->print_menu_0();

	$config_form->set_submit_value( _WEBLINKS_UPDATE );
	$config_form->init_form();

	echo '<a name="form_template"></a>'."\n";
	echo "<h4>"._AM_WEBLINKS_CONF_TEMPLATE."</h4>\n";
	echo _AM_WEBLINKS_CONF_TEMPLATE_DESC."<br /><br />\n";
	$config_form->show_form_template( _AM_WEBLINKS_CONF_TEMPLATE );
}

weblinks_admin_print_footer();
xoops_cp_footer();
exit();
// --- main end ---

?>